from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User


@login_required(login_url='login')
def personalCenter(request):
    if request.method == "POST":
        first_name = request.POST.get("first_name")
        passWord = request.POST.get("password")
        User.objects.filter(id=request.user.id).update(first_name=first_name)
        if passWord == "":
            return render(request, 'personal_center.html', {"result": "失败"})
        else:
            u = User.objects.get(username=request.user.username)
            u.set_password(passWord)
            u.save()
    return render(request, 'personal_center.html')
